/*

 * BTreeTest.cpp
 *
 *  Created on: Nov 11, 2011
 *      Author: jjs


#include <iostream>
#include <fstream>
#include <sstream>
#include <iterator>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <string>

#include <stx/btree.h>
using namespace std;

struct traits_nodebug
{
    static const bool       selfverify = true;
    static const bool       debug = false;

    static const int        leafslots = 8;
    static const int        innerslots = 8;
};

//holds the data in the leafs of the bTree
struct data_struct
    {
		double pointID;
		std::vector<double> points;
		data_struct(double in_pointID, std::vector<double> in_points){

			pointID = in_pointID;

			while(!in_points.empty())
			{
				points.push_back(in_points.back());
			}

		}
    };

typedef struct data_struct         data_type;

typedef stx::btree<float, data_type, float, less<float>, struct traits_nodebug, true, allocator<float> > btree_type;
btree_type bt;

//finds all key values between min and max
void rangeSearch(float min, float max)
{
	cout << "in rangeSearch min: "<<min<<" max: "<< max << endl;
	btree_type::iterator bi = bt.upper_bound(min);
    while(bi != bt.end() && bi.key() < max)
    {
   	 cout << bi.data().pointID << " ";
   	 bi++;
    }
}

std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) { 
    std::stringstream ss(s); 
    std::string item; 
    while(std::getline(ss, item, delim)) { 
        elems.push_back(item); 
    } 
    return elems; 
}
 
std::vector<std::string> split(const std::string &s, char delim) { 
    std::vector<std::string> elems; 
    return split(s, delim, elems); 
} 

class BadConversion : public std::runtime_error {
  public:
    BadConversion(std::string const& s)
      : std::runtime_error(s)
      { }
  };

  inline double convertToDouble(std::string const& s)
  {
    std::istringstream i(s);
    double x;
    if (!(i >> x))
      {
    	cout << ("Error: convertToDouble(\"" + s + "\")");
    	exit(1);
      }
    return x;
  } 

int main (int argc, char* argv[]) { 
    bt.verify();
   cout << "argc = " << argc << endl; 

   bool hasInputFileArgument = false;

   for(int i = 0; i < argc; i++) 
   {
	   switch (i) {
	   case 0:
		   cout << "Executable : " << argv[i] << endl;
		   break;
	   case 1:
			cout << "Mode : " << argv[i] << endl;
			break;
	   case 2:
			cout << "FileName : " << argv[i] << endl;
			hasInputFileArgument = true;
			break;
	   default:
			cout << "Unknown parameter : " << argv[i] << endl;
			break;
	   }
   }

   if(hasInputFileArgument)
   {
	   double dPointValue = 0.0;
	   string line;
	   //open file
	   ifstream inputFile("samplePoints.txt");
	   if(inputFile.is_open())
	   {
		   //read till eof
		   while(!inputFile.eof())
		   {
			   //read the line
			   getline(inputFile, line);
			   //split the line on , 
			   std::vector<std::string> x = split(line, ',');
			   std::vector<double> points;
			   //output line
			   bool isAttributeID = true;
			   //iterate over the split line
			   for(vector<string>::iterator val = x.begin();
				   val != x.end(); ++val)
			   {
				   if(isAttributeID){
					   //Attribute ID, not sure what to do with this ID, convert to a double
					   dPointValue = convertToDouble(*val);
					   isAttributeID = false;					   
					   cout << "Attribute ID: " << convertToDouble(*val) << endl;
				   }
				   else
				   {
					   //Dimension point, convert to a double
					   //points.insert(convertToDouble(*val));
					   //insert value into the b tree
					   points.push_back(convertToDouble(*val));
				   }
			   }
			   //insert value into b tree
			   bt.insert(dPointValue, data_type(dPointValue,points) );
		   }
		   //close file
		   inputFile.close();
	   }
	   else 
		   cout << "Unable to open file"; 
   }


   ofstream outputFile ("output.txt");

   bt.dump(outputFile);
   outputFile.close();
   cout << "Testing a B+Tree!\n";


         cout << "btree size: " << bt.size() << endl << endl;

         //see if a couple values are in the tree
         cout << "Does 2.23 exist? ";
         if(bt.exists(2.23))
        	 cout << "yes\n";
         else
        	 cout << "no\n";

         cout << "Does 2.7 exist? ";
         if(bt.exists(2.7))
        	 cout << "yes\n";
         else
             cout << "no\n";

         cout << endl;

         //delete 2.23 then search for it
         cout << "btree size: " << bt.size() << endl;
         cout << "Deleting 2.23\n";
         if(bt.erase_one(2.23))
        	 cout << "Deleted 2.23\n";
         else
        	 cout << "Failed to delete 2.23\n";
         cout << "btree size: " << bt.size() << endl;
         cout << "Does 2.23 exist? ";
         if(bt.exists(2.23))
        	 cout << "yes\n";
         else
        	 cout << "no\n";

         cout << endl;

         //try to delete a value not in the tree
         cout << "btree size: " << bt.size() << endl;
         cout << "Deleting 5.33\n";
         if(bt.erase_one(5.33))
        	 cout << "Deleted 2.33\n";
         else
        	 cout << "Failed to delete 5.33\n";
         cout << "btree size: " << bt.size() << endl;

         //do a range search
         cout << endl << "range search 2.3 - 3.3" << endl;
         rangeSearch(2.3,3.3);

		 int input;
		 cin >> input;
  return 0;
}



*/
